import 'package:dynamic_stock/pages/login.dart';
import 'package:dynamic_stock/root/root_page.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'const/const.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  Widget root = Container(
    color: Colors.white,
  );
  @override
  void initState() {
    super.initState();
    _load();
  }

  _load() async {
    SharedPreferences share = await SharedPreferences.getInstance();
    if(share.getString(USER_CACHE_KEY) == null) {
      setState(() {
        root = LoginScreen();
      });
      
    } else {
      setState(() {
        root = RootPage();
      });
    }
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primaryColor: Colors.white
      ),
      home: root
    );
  }
}




